package com.example.tencentdemo.controller;

import com.example.tencentdemo.entity.ChatAdmin;
import com.example.tencentdemo.service.Impl.ChatAdminImpl;
import com.example.tencentdemo.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/chatAdmin")
public class ChatAdminController {
    @Autowired
    private com.example.tencentdemo.service.Impl.ChatAdminImpl ChatAdminImpl;
    @PostMapping("/insert")
    public Result<ChatAdmin> insertAdmin(@RequestBody ChatAdmin chatAdmin){
        try {
            int i = ChatAdminImpl.insertChatAdmin(chatAdmin);
            if (i == 0){
                return Result.success();
            }else{
                return Result.success(chatAdmin);
            }
        } catch (Exception e) {
            System.out.println(e);
            return Result.internalServerError("内部服务器错误,新建成员与管理员聊天失败");
        }

    }
    @PostMapping("/queryPeople")
    public Result<List<ChatAdmin>> query(@RequestParam String admin_id){
        try {
            List<ChatAdmin> chatAdmins = ChatAdminImpl.selectChatPeople(admin_id);
            if(chatAdmins.isEmpty()){
                return Result.notFound("查找不到与该管理员聊天的用户");
            }else{
                return Result.success(chatAdmins);
            }
        } catch (Exception e) {
            System.out.println(e);
            return Result.internalServerError("内部服务器错误,查找成员与管理员聊天列表失败");
        }
    }
}
